﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Bussiness.Entity;
using Bussiness.Manager;
using WB.Library;
public partial class Admin_Category_CategoryList : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["control"] == "ncat")
                CatType = "NEWS";
            else
                CatType = "PROD";
            LoadCategoryList();
           
          //  Response.Write("lang:" + Language + ";CatType:" + CatType);
        }
    }
    /// <summary>
    /// Loai category : NEWS, PROD
    /// </summary>
    public string CatType
    {
        get { return hidCatType.Value; }
        set
        {
            hidCatType.Value = value;
            switch (hidCatType.Value)
            {
                case "NEWS": lblTitle.Text = "DANH MỤC TIN TỨC";
                    break;
                case "PROD": lblTitle.Text = "DANH MỤC SẢN PHẨM";
                    break;

            }
        }
    }

    /// <summary>
    /// Loai category : NEWS, PROD
    /// </summary>
    public string Language
    {
        get { return hidLang.Value; }
        set
        {
            hidLang.Value = value;
            switch (CatType)
            {
                case "NEWS": lblTitle.Text = "DANH MỤC TIN TỨC";
                    break;
                case "PROD": lblTitle.Text = "DANH MỤC SẢN PHẨM";
                    break;

            }
        }
    }
    public string GetDetailLink(object id)
    {
        switch (CatType)
        {
            case "NEWS": return "?control=addncat&id=" + id;
                break;
            case "PROD": return "?control=addprocat&id=" + id;
                break;

        }
        return "#";
    }
    public void LoadCategoryList()
    {

        DataTable tbl = CmsCategoryManager.CreateInstant().GetCategoryListByLang(CatType, Language);
        rep.DataSource = tbl;
        rep.DataBind();
    }

    protected void rep_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "del":
                CmsCategoryManager.CreateInstant().DeleteById(FGuid.ToGuid(e.CommandArgument.ToString()));
                CmsCategoryInfosManager.CreateInstant().DeleteByCategoryId(FGuid.ToGuid(e.CommandArgument.ToString()));
                LoadCategoryList();
                break;
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        switch (CatType)
        {
            case "NEWS": Response.Redirect( "?control=addncat");
                break;
            case "PROD": Response.Redirect( "?control=addprocat");
                break;

        }
      
    }
}
